package net.aiion.weave.spi.resources;

import java.util.ServiceLoader;

public abstract class ResourceFactory
{
    private static ResourceFactory instance;

    public ResourceFactory() {
    }

    public abstract Resource createResource(String aResourceName);

    public static ResourceFactory getInstance() {
        if (instance == null) {
            for (ResourceFactory resourceFactory : ResourceFactoryServiceLoader.SERVICE_LOADER) {
                instance = resourceFactory;
                break;
            }
        }

        return instance;
    }

    private static final class ResourceFactoryServiceLoader
    {
        private static final ServiceLoader<ResourceFactory> SERVICE_LOADER = ServiceLoader.load(ResourceFactory.class);

        private ResourceFactoryServiceLoader() {
        }
    }
}
